# coding:utf-8
import turtle
import math


def drawDot(x, y):
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
    turtle.dot(4)


def drawRect(x, y, length, width, filled):
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
    if filled:
        turtle.begin_fill()
    for i in range(0, 4):
        if i % 2 == 0:
            turtle.forward(length)
        else:
            turtle.forward(width)
        turtle.left(90)
    if filled:
        turtle.end_fill()
    pass


def drawParalleRect(x, y, length, width, angle, filled):
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
    if filled:
        turtle.begin_fill()
    for i in range(0, 4):
        if i % 2 == 0:
            turtle.forward(length)
            turtle.left(180 - angle)
        else:
            turtle.forward(width)
            turtle.left(angle)
    if filled:
        turtle.end_fill()
    pass


def drawTriangle(x, y, longestLength, filled):
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()

    if filled:
        turtle.begin_fill()
    turtle.forward(longestLength)
    turtle.left(135)
    turtle.forward(math.sqrt(longestLength ** 2 / 2))
    turtle.left(90)
    turtle.forward(math.sqrt(longestLength ** 2 / 2))
    turtle.left(135)
    if filled:
        turtle.end_fill()
    pass


def drawCrossRect(x, y, length, width, filled):
    drawRect(x, y, length, width, filled)

    if filled:
        turtle.begin_fill()
    turtle.penup()
    turtle.goto(x + length / 2, y)
    turtle.pendown()
    turtle.setheading(90)
    turtle.forward(width)

    turtle.penup()
    turtle.goto(x, y + width / 2)
    turtle.pendown()
    turtle.setheading(0)
    turtle.forward(width)
    if filled:
        turtle.end_fill()
    pass


def drawWindows(x, y, length, filled):
    turtle.fillcolor("#FFFFFF")
    drawCrossRect(x, y, length, length, filled)
    turtle.fillcolor("#D3C3B7")
    drawRect(x - 3, y - 5, length + 6, 5, filled)


if __name__ == "__main__":
    turtle.speed(0)
    turtle.shape("blank")
    turtle.setup(800, 600)
    # 基座
    turtle.fillcolor("#615852")
    drawRect(-150, -190, 300, 10, True)
    # 侧墙
    turtle.fillcolor("#ECE1D2")
    drawRect(-135, -180, 80, 160, True)
    # 侧墙顶
    drawTriangle(-135, -20, 80, True)
    # 屋顶
    turtle.fillcolor("#695439")
    drawParalleRect(-55, -20, 190, math.sqrt(2 * 40 ** 2), 45, True)
    # 正墙
    turtle.fillcolor("#ECE1D2")
    drawRect(-55, -180, 190, 160, True)
    # 侧墙窗户
    for i in range(0, 3):
        drawWindows(-105, -50 - 40 * i, 20, True)
    # 正墙窗户
    for i in range(0, 3):
        for j in range(0, 4):
            drawWindows(-30 + 40 * j, -50 - 40 * i, 20, True)
    turtle.fillcolor("#695439")
    drawRect(-10, -150, 100, 10, True)
    turtle.fillcolor("#FFFFFF")
    for i in range(0, 4):
        drawRect(0 + 20 * i, -180, 20, 30, True)

    drawDot(4, -180 + 15)
    drawDot(36, -180 + 15)
    drawDot(44, -180 + 15)
    drawDot(76, -180 + 15)
    turtle.hideturtle()
    turtle.done()
    pass
